home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Developers / apps.to.go / DTS.StyleChat / IdleTasks.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-12  |  3.2 KB  |  125 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** File:        IdleTasks.c
  5. ** Written by:    Eric Soldan
  6. **
  7. ** Copyright © 1990-1993 Apple Computer, Inc.
  8. ** All rights reserved.
  9. */
  10.  
  11. /* You may incorporate this sample code into your applications without
  12. ** restriction, though the sample code has been provided "AS IS" and the
  13. ** responsibility for its operation is 100% yours.  However, what you are
  14. ** not permitted to do is to redistribute the source as "DSC Sample Code"
  15. ** after having made changes. If you're going to re-distribute the source,
  16. ** we require that you make it clear in the source that the code was
  17. ** descended from Apple Sample Code, but that you've made changes. */
  18.  
  19. /* This function is called when a null event is received.  Do appropriate tasks
  20. ** for null event situations, such as handling balloon help for window. */
  21.  
  22.  
  23.  
  24. /*****************************************************************************/
  25.  
  26.  
  27.  
  28. #include "App.h"            /* Get the application includes/typedefs, etc.    */
  29. #include "App.protos.h"        /* Get the prototypes for application.            */
  30.  
  31. extern OSType    gAppWindowType;
  32. extern short    gDialogErr;
  33.  
  34. Boolean            gStartingUp = true;
  35.  
  36.  
  37.  
  38. /*****************************************************************************/
  39. /*****************************************************************************/
  40.  
  41.  
  42.  
  43. #pragma segment Main
  44. void    DoIdleTasks(EventRecord *event)
  45. {
  46. #ifndef __MWERKS__
  47. #pragma unused (event)
  48. #endif
  49.  
  50.     WindowPtr        ww;
  51.     FileRecHndl        ff;
  52.     ControlHandle    ctl;
  53.     EventRecord        evt;
  54.     TEHandle        te;
  55.     Rect            rr;
  56.     KeyMap            kk;
  57.     short            mm;
  58.  
  59.     static long    waitSome;
  60.  
  61.     if (gStartingUp) {
  62.         if (FrontWindow()) {
  63.             gStartingUp = false;
  64.             waitSome = 0;
  65.             IsCtlEvent(nil, event, nil, nil);
  66.             return;
  67.         }
  68.         if (!waitSome) waitSome = TickCount() + 30;
  69.         else {
  70.             if (waitSome < TickCount()) {
  71.                 gStartingUp = false;
  72.                 waitSome    = 0;
  73.                 gDialogErr  = NewDocumentWindow(nil, gAppWindowType, true);
  74.                 if (gDialogErr)
  75.                     NewDocumentWindow(nil, 'ERR#', false);
  76.             }
  77.         }
  78.         IsCtlEvent(nil, event, nil, nil);
  79.         return;
  80.     }
  81.  
  82.     for (ww = nil; (ww = GetNextWindow(ww, gAppWindowType)) != nil;) {
  83.         ff = (FileRecHndl)GetWRefCon(ww);
  84.         if ((*ff)->connect.connected == 1) {
  85.             CNum2Ctl(ww, 1010, &ctl);
  86.             (*ctl)->contrlVis = false;
  87.             BeginFrame(ww);
  88.             CNum2Ctl(ww, 1020, &ctl);
  89.             ShowStyledControl(ctl);
  90.             CNum2Ctl(ww, 1000, &ctl);
  91.             ShowStyledControl(ctl);
  92.             EndFrame(ww);
  93.             (*ff)->connect.connected++;
  94.             BeginContent(ww);
  95.             SendMessage(ff, kStylMssg);
  96.             SendMessage(ff, kTextMssg);
  97.             EndContent(ww);
  98.         }
  99.     }
  100.  
  101.     if (TSMTEAvailable()) TSMEvent(event);
  102.  
  103.     GetKeys(kk);
  104.     mm  = (kk[1] & 0x8000) ? (cmdKey    ) : 0;
  105.     mm |= (kk[1] & 0x0004) ? (optionKey ) : 0;
  106.     mm |= (kk[1] & 0x0008) ? (controlKey) : 0;
  107.     mm |= (kk[1] & 0x0001) ? (shiftKey  ) : 0;
  108.     evt.what      = nullEvent;        /* Make valid null event, with modifiers. */
  109.     evt.modifiers = mm;
  110.     IsCtlEvent(nil, &evt, nil, nil);
  111.  
  112.     ww = CTETargetInfo(&te, &rr);
  113.     if (ww) {
  114.         if (rr.left < -8192)        /* If TextEdit control is in the frame...  */
  115.             BeginFrame(ww);            /* Set clipping to the frame area.           */
  116.         else
  117.             BeginContent(ww);        /* Else set clipping to the document area. */
  118.         CTEIdle();
  119.         EndContent(ww);                /* EndContent can be used to close a BeginFrame. */
  120.     }
  121. }
  122.  
  123.  
  124.  
  125.